package com.jp.kefu;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableScheduling
@EnableSwagger2
@MapperScan({"com.jp.kefu.dao"})
public class KefuApplication {

    public static void main(String[] args) {
	   SpringApplication.run(KefuApplication.class, args);
    }


    // 使用RestTemplateBuilder来实例化RestTemplate对象，spring默认已经注入了RestTemplateBuilder实例
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
	   return builder.build();
    }



    @Bean
    public Docket config() {
	   return new Docket(DocumentationType.SWAGGER_2)
			 .apiInfo(apiInfo())
			 .useDefaultResponseMessages(false)
			 .select()
			 .apis(RequestHandlerSelectors.basePackage("com.jp.kefu.web.controller"))
			 .build();
    }

    private ApiInfo apiInfo() {
	   return new ApiInfoBuilder()
			 .title("客服系统API文档")
			 .contact(new Contact("作者", "访问地址", "联系方式"))
			 .build();
    }

	/*---------mybatis---------*/
    /*@Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
	   MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
	   mapperScannerConfigurer.setBasePackage("com.jp.kefu.dao");
	   return  mapperScannerConfigurer;

    }*/

    @Bean
    public ProviderInterceptor providerInterceptor(){
        return new ProviderInterceptor();
    }


}
